<%@page contentType="text/html; charset=utf-8" %>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<%@ include file="/commons/validation.jsp"%>
<html>
<head>
<link href="${ctx}/styles/aux_window.css" rel="stylesheet" type="text/css">
<link href="${ctx}/styles/listTable.css" rel="stylesheet" type="text/css">


<script type="text/javascript" src="${ctx }/scripts/public3.js"></script>
<script type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>



<script type="text/javascript">
	function openAdd(){//打开添加
	    var second_employeeId = $('second_employeeId').value;
		var url = "${ctx}/system_fitmentApproveSetupAction.do?method=initAdd&second_employeeId="+second_employeeId;
		top.windowOpen(url,"add","装修一级审批",230,450,true,"addFrame");
	}
	function openDelete(){ // 删除
		var currentID = document.frames('listFrame').currentID;

		if(currentID == null || currentID ==""){
			Alert("请选择要删除的记录");
			return;
		}

		var url = "${ctx}/system_fitmentApproveSetupAction.do?method=checkDelete";
		var params = "";
		sendAjaxRequest(url,params,function(response){
		  		var flag = response.responseText;
				if( flag == 'true'){
					AskConfirm("您确认删除此条记录吗?","renovationFrame","_delete");
				}else{
					Alert("不能进行删除，至少要有一条数据！");
				}
		});
	}
	function _delete(){
		var url = "${ctx}/system_fitmentApproveSetupAction.do?method=delete";
		var params = "employeeId=" + document.frames('listFrame').currentID;
		sendAjaxRequest(url,params,function(result){
			ajaxSubmitException(result.responseText);
			flushList();
		});
	}
	function flushList(){
		var url = "${ctx}/system_fitmentApproveSetupAction.do?method=list";
		document.getElementById("listFrame").src = url;
	}
/***************选择人*****************/
	var currentPerson; //当前的人
	function openSelectPerson(){ //打开选人的界面
	  	var url = "${ctx}/common_employeeQuery.do?method=initSelectPsrsonMain";
	  	url += "&frameName=renovationFrame";
	  	url += "&callBack=setPersonInfo";
	  	url += "&multiple=false";
		top.windowOpen(url, "selectPerson", "选人", 530, 700,true,"selectPerson");
	}
	function setPersonInfo(info){ //设置选人信息
		var personInfos = info.split(";");
		for(var i = 0; i < personInfos.length; i++){
			var temp = personInfos[0].split(",");
			$(currentPerson + '_employeeId').value= temp[0];
			$(currentPerson + '_employeeName').value = temp[1];
			setJob();
			$('second_employeeName').fireEvent("onblur");
		}
	}
	function setJob(){
		var employeeId = $(currentPerson + '_employeeId').value;
		var url = "${ctx}/system_fitmentApproveSetupAction.do?method=getJob";
		var params = "employeeId=" + employeeId;
		sendAjaxRequest(url,params,function(result){
			ajaxSubmitException(result.responseText);
			$(currentPerson + "_job_show").innerText = result.responseText;
			$(currentPerson + "_job").value = result.responseText;
		});
	}

	function clearEmployeeInfo(response){ //验证失败，清除信息
		var json = response.responseText;
		validationAlert("second_employeeName",false,json);
	}
	/*************表单提交****************/
	function submitForm(){
		var flag =	$("mainFrom").fireEvent("onsubmit");
		if(!flag) return;
		//$("mainFrom").submit();
		var url = $("mainFrom").action;
		var params = $("mainFrom").serialize();
		new Ajax.Request(
                url,
                {method: 'post', parameters: params, asynchronous:false,onComplete:	function (result){
					ajaxSubmitException(result.responseText);
					SuccessAlert("操作成功");
					init();
				}
                });
	}

	function checkApprove(){
		var isTrue=$("mainFrom").fireEvent("onSubmit");
  		if(!isTrue)
  		return true;  //不通过验证，直接关闭

		var url = "${ctx}/system_fitmentApproveSetupAction.do?method=checkData";
		var params = "secondEmployeeId=" + $('second_employeeId').value;
			params +="&depositEmployeeId=" + $('deposit_employeeId').value;
			params +="&precinctId=" + $('precinctId').value;

		 new Ajax.Request(
	                    url,
	                    {
	                    	method: 'post',
	                    	parameters: params,
	                    	asynchronous:false,
	                    	onComplete:back
	                    });
	}

	var appFlag;

	function back(result){

		ajaxSubmitException(result.responseText);
		var flag =result.responseText;
		if(flag == 'true'){
			this.appFlag = true;
		}else{
			this.appFlag = false;
		}
	}

	function init(){
		parent.marker = 3;
		onPrecinctChange($('precinctId'));
	}

	//期数改变
	function onPrecinctChange(thiz){
		selectId = thiz.options[thiz.selectedIndex].value;
		$('listFrame').src = "${ctx}/system_fitmentApproveSetupAction.do?method=initList&precinctId="+selectId;

		new Ajax.Request(
                "${ctx}/system_fitmentApproveSetupAction.do?method=getApproveSetupData&precinctId="+selectId,
                {method: 'post', asynchronous:false,onComplete:	function (result){
					//ajaxSubmitException(result.responseText);
					//alert(result.responseText);
					var obj = eval('(' + result.responseText + ')');

					$('second_employeeName').value = (obj.second==null ? "" : obj.second.employeeName );
					$('second_employeeId').value =  (obj.second==null ? "" : obj.second.employeeId );
					$('second_job_show').innerText = (obj.second==null ? "" : obj.second.job );
					$('second_bussinessProcessId').innerText = (obj.second==null ? "" : obj.second.bussinessProcessId );

					$('deposit_employeeName').value = (obj.deposit==null ? "" : obj.deposit.employeeName );
					$('deposit_employeeId').value = (obj.deposit==null ? "" : obj.deposit.employeeId );
					$('deposit_job_show').innerText = (obj.deposit==null ? "" : obj.deposit.job );
					$('deposit_bussinessProcessId').innerText = (obj.deposit==null ? "" : obj.deposit.bussinessProcessId );


				}
                });

      $('listFrame').location.reload();
	}
</script>
</head>
<body onload="init();">
<form id="mainFrom" name="mainFrom" method="post" class="required-validate"
	action="${ctx}/system_fitmentApproveSetupAction.do?method=update">
<div style="overflow:auto; height:300px;">
  <div id="table06" class="tab_line">
    <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
      <tr>
            <td colspan="4" class="aux_titletable">装修申请审批&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;管理区：     	<pms:unitedSelect name="precinctId"
            					  id="precinctId"
            					  style="width:110px"
              					  dataList="${precinctList}"
              					  optionLabel="name"
              					  optionValue="keyword"
              					  className="select-one-required"
              					  onChange="onPrecinctChange(this)"
 									>
               </pms:unitedSelect> </td>
      </tr>
      <tr>
        <td colspan="4" class="aux_intable_td1"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="tab_line">
            <tr>
              <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" >
                  <tr>
                    <td class="bg_toolBar"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td align="left">一级审批人：</td>
                          <td width="35%" align="right">
                          	<table border="0" cellpadding="0" cellspacing="0" id="ico1">
                              <tr>
                                <td class="toolbarico">
                                	<a href="#"  onclick="openAdd();" onfocus="this.blur()">
                                		<img src="${ctx}/images/ico_newfile.gif" border="0" align="absbottom" alt="新建"/>&nbsp;
                                	</a>
                                </td>
                                <td class="toolbarico">
                                	<a href="#" onClick="openDelete();" onFocus="this.blur()">
                                		<img src="${ctx}/images/ico_delete.gif" alt="删除" width="16" height="16" border="0" align="absbottom" />
                                	</a>
                                </td>
                                <td  class="toolbarico">&nbsp;</td>
                              </tr>
                          </table>
                          </td>
                        </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td colspan="5" >
						<iframe id="listFrame" name="listFrame" width="100%" frameborder="0"
							src="${ctx}/system_fitmentApproveSetupAction.do?method=initList">
						</iframe>
                      </td>
                  </tr>
              </table></td>
            </tr>

        </table></td>
      </tr>
	  <tr>
               <td class="aux_intable_td1">二级审批人姓名：</td>
               <td class="aux_intable_require"><table border="0" cellspacing="0" cellpadding="0">
                   <tr>
                     <td>
                     	<input id="second_employeeName" name="second_employeeName" type="text"
                     	   	class="required validate-ajax" size="16"
                     	   	relativeId="second_employeeId"
	                	   	onSuccess="setJob"
	                	   	onFailure="clearEmployeeInfo"
                           	validateUrl="${ctx}/system_fitmentApproveSetupAction.do?method=checkSecondEmployee"
                     		readonly="readonly"
                     		value="${second.employeeName}"
                     		afterInsert="second_employeeNameSpan"
                     		/>
                     	<input id="second_employeeId" name="second_employeeId" value="${second.employeeId}" type="hidden">
                     	<input id="second_bussinessProcessId" name="second_bussinessProcessId" value="${second.sysrefKeyword}" type="hidden">
                     </td>
                     <td width="4">&nbsp;</td>
                     <td>
                     	<a href="#"  onClick="currentPerson='second';openSelectPerson();" onFocus="this.blur()">
                     		<img src="${ctx}/images/ico_cz.gif" width="16" height="16" border="0" />
                     	</a>
                     	<span id="second_employeeNameSpan"></span>
                     </td>
                   </tr>
               </table></td>
               <td class="aux_intable_td1">职 位：</td>
               <td class="aux_intable_td2">
               		<span id="second_job_show" name="second_job_show">
               			${second.job}
               		</span>
               		<input id="second_job" name="second_job" type="hidden" value="${second.job}">
               	</td>
            </tr>
			<tr>
            <td colspan="4" class="aux_titletable">保证金核算审批</td>
      </tr>
	  <tr>
               <td class="aux_intable_td1">审批人姓名：</td>
               <td class="aux_intable_require"><table border="0" cellspacing="0" cellpadding="0">
                   <tr>
                     <td>
                     	<input id="deposit_employeeName" name="deposit_employeeName" type="text" class="inputtext validate-char required"  size="16" readonly="readonly"
                     		value="${deposit.employeeName}"/>
                     	<input id="deposit_employeeId" name="deposit_employeeId" type="hidden" value="${deposit.employeeId}">
                     	<input id="deposit_bussinessProcessId" name="deposit_bussinessProcessId" value="${deposit.bussinessProcessId}" type="hidden">
                     </td>
                     <td width="4">&nbsp;</td>
                     <td>
                     	<a href="#"  onClick="currentPerson='deposit';openSelectPerson();" onFocus="this.blur()">
                     		<img src="${ctx}/images/ico_cz.gif" width="16" height="16" border="0" />
                     	</a>
                     </td>
                   </tr>
               </table></td>
               <td class="aux_intable_td1">职 位：</td>
               <td class="aux_intable_td2">
               	  <span id="deposit_job_show" name="deposit_job_show">
               		${deposit.job}
               	  </span>
               	  <input id="deposit_job" name="deposit_job" type="hidden" value="${deposit.job}">
               </td>
            </tr>
</form>
			<tr>
             <td colspan="4" class="window_footer"><table border="0" cellpadding="0" cellspacing="0">
               <tr>
                 <td class="btn_between_space"></td>
                 <td class="buttonOffLeft" id="btn1_31"></td>
                 <td class="buttonOffMiddle" id="btn1_32"
                 	 onClick="submitForm();"
                 	 onMouseOver="btn_change_over(3)"
                 	 onMouseOut="btn_change_out(3)"
                 	 onBlur="btn_change(3)">

                 	 <img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom" />
                 	 保 存
                 </td>
                 <td class="buttonOffRight" id="btn1_33"></td>
               </tr>
             </table>
               <p>&nbsp;</p></td>
  </tr>
    </table>
  </div>
  </div>
</body>
</html>